package com.ruoyi.web.controller.novel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNovelCarousel;
import com.ruoyi.system.service.ISysNovelCarouselService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播列表Controller
 * 
 * @author ZouYangMing
 * @date 2022-11-08
 */
@RestController
@RequestMapping("/novel/carousel")
public class SysNovelCarouselController extends BaseController
{
    @Autowired
    private ISysNovelCarouselService sysNovelCarouselService;

    /**
     * 查询轮播列表列表
     */
    //@PreAuthorize("@ss.hasPermi('novel:carousel:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(SysNovelCarousel sysNovelCarousel)
    {
        startPage();
        List<SysNovelCarousel> list = sysNovelCarouselService.selectSysNovelCarouselList(sysNovelCarousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播列表列表
     */
    @PreAuthorize("@ss.hasPermi('novel:carousel:export')")
    @Log(title = "轮播列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNovelCarousel sysNovelCarousel)
    {
        List<SysNovelCarousel> list = sysNovelCarouselService.selectSysNovelCarouselList(sysNovelCarousel);
        ExcelUtil<SysNovelCarousel> util = new ExcelUtil<SysNovelCarousel>(SysNovelCarousel.class);
        util.exportExcel(response, list, "轮播列表数据");
    }

    /**
     * 获取轮播列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:carousel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysNovelCarouselService.selectSysNovelCarouselById(id));
    }

    /**
     * 新增轮播列表
     */
    @PreAuthorize("@ss.hasPermi('novel:carousel:add')")
    @Log(title = "轮播列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNovelCarousel sysNovelCarousel)
    {
        return toAjax(sysNovelCarouselService.insertSysNovelCarousel(sysNovelCarousel));
    }

    /**
     * 修改轮播列表
     */
    @PreAuthorize("@ss.hasPermi('novel:carousel:edit')")
    @Log(title = "轮播列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNovelCarousel sysNovelCarousel)
    {
        return toAjax(sysNovelCarouselService.updateSysNovelCarousel(sysNovelCarousel));
    }

    /**
     * 删除轮播列表
     */
    @PreAuthorize("@ss.hasPermi('novel:carousel:remove')")
    @Log(title = "轮播列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysNovelCarouselService.deleteSysNovelCarouselByIds(ids));
    }
}
